import { useImmer  } from "use-immer";
import QuesaItem, { QuestionType } from './components/QuesaItem';
import { Input } from "antd";
import { useTitle } from 'ahooks';

const list = [
  {
    _id: '1',
    title: '问卷1',
    answerCount: 2,
    isPublished: false,
    createTime: '2025-04-27',
    isCollect: true
  },
  {
    _id: '2',
    title: '问卷2',
    answerCount: 65,
    isPublished: true,
    createTime: '2025-04-27',
    isCollect: false
  }
]
function PageEntry() {
  useTitle('问卷列表 - 我的问卷');
  const [tableList, setTableList] = useImmer<QuestionType[]>(list)

  function handleAdd() {
    setTableList(dart => {
      const id = Math.random().toString().slice(-3);
      dart.push({
        _id: id,
        title: '问卷' + id,
        answerCount: 2,
        isPublished: false,
        createTime: '2025-04-27',
        isCollect: false
      })
    })
  }

  return (
    <div className="p-10px">
      <div className="flex items-center justify-between">
        <h2>我的问卷</h2>
        <div>
          <Input type="text" placeholder="请输入问卷名称" />
        </div>
      </div>
      <div>
        {tableList.map(item => <QuesaItem key={item._id} question={item} />)}
      </div>
    </div>
  )
}

export default PageEntry;